// 云函数入口文件
const cloud = require('wx-server-sdk')

cloud.init()
const db=cloud.database();
const _ = db.command


// 云函数入口函数
//1是回帖，0是赞
exports.main = async (event, context) => {
  var id=event.id
  var type=event.type
  console.log(id,type);
  if(type==1){
    return await db.collection("topic").doc(id).update({
      data:{
        'topicReplyCount':_.inc(1),
        'lastReplytime':Date.parse(new Date())/1000
      }
    })

  }
  else{
    return await db.collection("reply").doc(id).update({
      data:{
        'rLikes':_.inc(1)
      }
    })

  }
}